package com.koron.order.risk.base.service.impl;


import cn.hutool.core.collection.CollUtil;
import com.koron.order.risk.base.bean.po.LineStaff;
import com.koron.order.risk.base.mapper.LineStaffMapper;
import com.koron.order.risk.base.service.LineStaffService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 线路人员表(LineStaff)表服务实现类
 *
 * @author jzp
 * @since 2022-12-22 16:37:46
 */
@Service
public class LineStaffServiceImpl implements LineStaffService {

    /**
     * 通过ID查询单条数据
     *
     */
    @Override
    @TaskAnnotation("getById")
    public LineStaff getById(SessionFactory factory, String id) {
        LineStaffMapper mapper = factory.getMapper(LineStaffMapper.class);
        return mapper.selectById(id);
    }

    /**
     * 查询所有数据
     *
     */
    @Override
    @TaskAnnotation("list")
    public List<LineStaff> list(SessionFactory factory, LineStaff lineStaff) {
        LineStaffMapper mapper = factory.getMapper(LineStaffMapper.class);
        return mapper.selectList(lineStaff);
    }

    @Override
    @TaskAnnotation("listByOrderId")
    public List<LineStaff> listByOrderId(SessionFactory factory, String orderId) {
        LineStaff lineStaff = new LineStaff();
        lineStaff.setOrderId(orderId);
        return list(factory, lineStaff);
    }

    @Override
    @TaskAnnotation("listByOrderIds")
    public List<LineStaff> listByOrderIds(SessionFactory factory, List<String> orderIds) {
        LineStaff lineStaff = new LineStaff();
        lineStaff.setOrderIds(orderIds);
        return list(factory, lineStaff);
    }

    /**
     * 新增数据
     *
     */
    @Override
    @TaskAnnotation("save")
    public boolean save(SessionFactory factory, LineStaff lineStaff) {
        LineStaffMapper mapper = factory.getMapper(LineStaffMapper.class);
        return mapper.insertOrUpdate(lineStaff) > 0;
    }

    @Override
    @TaskAnnotation("saveBatch")
    public boolean saveBatch(SessionFactory factory, List<LineStaff> lineStaffs) {
        if (CollUtil.isEmpty(lineStaffs)) {
            return false;
        }
        LineStaffMapper mapper = factory.getMapper(LineStaffMapper.class);
        return mapper.insertOrUpdateBatch(lineStaffs) > 0;
    }

    /**
     * 修改数据
     *
     */
    @Override
    @TaskAnnotation("update")
    public boolean update(SessionFactory factory, LineStaff lineStaff) {
        LineStaffMapper mapper = factory.getMapper(LineStaffMapper.class);
        return mapper.update(lineStaff) > 0;
    }

    /**
     * 通过主键删除数据
     *
     */
    @Override
    @TaskAnnotation("deleteById")
    public boolean deleteById(SessionFactory factory, String id) {
        LineStaffMapper mapper = factory.getMapper(LineStaffMapper.class);
        return mapper.hidden(id) > 0;
    }

    @Override
    @TaskAnnotation("removeByOrderId")
    public boolean removeByOrderId(SessionFactory factory, String orderId) {
        LineStaffMapper mapper = factory.getMapper(LineStaffMapper.class);
        return mapper.removeByOrderId(orderId) > 0;
    }

}
